package com.szj.spushrtmp.push;

import android.view.SurfaceView;

import androidx.appcompat.app.AppCompatActivity;

/**
 * @ClassName: SPush
 * @Author: s10g
 * @CreateDate: 7/28/23$ 7:33 PM$
 * TODO
 */
public class SPush {
    static {
        System.loadLibrary("native-lib");
    }

    private final VideoChannel videoChannel;
    private final AudioChannel audioChannel;


    public SPush(AppCompatActivity activity, SurfaceView surfaceView) {
        // 初始化native SAudioChannel; SVideoChannel
        native_init();

        videoChannel = new VideoChannel(activity, surfaceView);
        audioChannel = new AudioChannel();


    }

    public void switchCamera() {
        videoChannel.switchCamera();
    }

    public void startPlay(String RTMPPath) {
        // 初始化RTMP
        native_startPlay(RTMPPath);

        // 视频开始播放
        videoChannel.startPlay();
        // 音频开始采集
        audioChannel.start();
    }

    public void stopPlay() {
        native_stopPlay();
        videoChannel.stopPlay();
        audioChannel.stop();
    }

    public void release() {
        native_release();
        videoChannel.release();
        audioChannel.release();
    }


    private native void native_init();

    /*
     * 作者:s10g
     * 创建时间: 8/3/23 10:28 AM
     * TODO 开始播放
     */
    private native void native_startPlay(String RTMPPath);

    /*
     * 作者:s10g
     * 创建时间: 8/3/23 10:28 AM
     * TODO 停止播放
     */
    private native void native_stopPlay();

    /*
     * 作者:s10g
     * 创建时间: 8/3/23 10:28 AM
     * TODO 释放资源
     */
    private native void native_release();

}
